package bishi2016;

import java.util.Scanner;

public class Jinzhi16to10 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string;
		char[] numbers;
		int[] numbersInt ;
		long jinzhi10 = 0;
		while(scanner.hasNext()){
			jinzhi10 = 0;
			string = scanner.nextLine().substring(2);
			numbers = string.toCharArray();
			numbersInt = new int[numbers.length];
			for (int i = 0; i < numbers.length; i++) {
				if(numbers[i] >= '0' && numbers[i] <= '9'){
					numbersInt[i] = numbers[i] - '0';
				}else {
					numbersInt[i] = numbers[i] - 'A' + 10;
				}
			}
			for (int i = 0; i < numbersInt.length; i++) {
				jinzhi10 += (long) (numbersInt[i] * Math.pow(16, numbersInt.length - 1 - i));
			}
			System.out.println(jinzhi10);
		}
		scanner.close();
	}
}
